package bishi.wangyi;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @Classname Main4
 * @Description TODO
 * @Date 2021/9/19 16:42
 * @Created by ASUS
 */
public class Main4 {

    static long q(int q, int n) {
        long res = 1;
        for (int i = 0; i < n; i++) res *= q;
        return res;
    }
    static long sum(int q, int n) {
        return (1 - q(q, n)) / (1 - q);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = Integer.parseInt(scanner.nextLine());
        List<Integer> nums = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            nums.add(Integer.parseInt(scanner.nextLine()));
        }
        for (int i = 0; i < num; i++) {
            int number = nums.get(i);
            boolean f = false;
            for (int j = 2; j < number && !f; j++) {
                for (int k = 0; k < 100000000 && !f; k++) {
                    if (sum(j, k) == number) {
                        System.out.println(k + " " + j);
                        f = true;
                    } else {
                        if (sum(j, k) > number) break;
                    }
                }
            }
        }
    }
}
